﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;

namespace MTSGui
{
    public static class BlockDataUpdater
    {

        public static void UpdateBlockData()
        {
            WebClient DownloadClient = new WebClient();
            try
            {
                Console.WriteLine("Getting new block data from http://mts.davejk.net/blocks/blockcolors.xml");

                DownloadClient.DownloadFile("http://mts.davejk.net/blocks/blockcolors.xml", "BlockColorsNew.xml");

                File.Delete(".\\BlockColors.xml");
                File.Copy(".\\BlockColorsNew.xml", ".\\BlockColors.xml");
                File.Delete(".\\BlockColorsNew.xml");
            }
            catch (Exception ex) 
            {
                TextWriter ErrorWriter = new StreamWriter("BlockUpdateFailure.txt");
                AssemblyName AppAssembly = Assembly.GetExecutingAssembly().GetName();
                ErrorWriter.WriteLine("MTS version:       " + AppAssembly.Version.ToString());
                ErrorWriter.WriteLine("Failure occurred:  " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString());

                ErrorWriter.WriteLine("Operating system:  " + Environment.OSVersion.ToString() + (Environment.Is64BitOperatingSystem ? " (64-bit)" : ""));
                ErrorWriter.WriteLine("CLR version:       " + Environment.Version.ToString());

                ErrorWriter.WriteLine(Environment.NewLine + "Please report what you did to cause this bug at http://minecraft.codeplex.com/WorkItem/Create," +
                    "attaching this file to the report." + Environment.NewLine);

                ErrorWriter.WriteLine(ex.ToString());

                ErrorWriter.Close();
            }
        }

    }
}
